package com.shrct.businessprocess.common.impl;

import com.shrct.businessprocess.common.RCTaskProxy;
import com.shrct.businessprocess.common.impl.RCTaskProxyImpl;
import com.shrct.businessprocess.organization.RCEmployee;
import edu.fudan.langlab.domain.organization.Party;
import edu.fudan.langlab.domain.task.Task;
import edu.fudan.langlab.domain.task.TaskEventListener;
import edu.fudan.mylang.pf.BaseService;
import edu.fudan.mylang.pf.IGenericQuery;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.stereotype.Service;

@Service("com.shrct.businessprocess.common.RCTaskService")
public class RCTaskServiceImpl extends BaseService implements TaskEventListener {
  public void afterTaskCreated(final Task task) {RCTaskProxy rCTaskProxy=RCTaskProxyImpl.create(getObjectFactory());
    final Procedure1<RCTaskProxy> _function = new Procedure1<RCTaskProxy>() {
        public void apply(final RCTaskProxy it) {
          it.setTask(task);
          Party _owner = task.getOwner();
          it.setOwner(((RCEmployee) _owner));
        }
      };
    ObjectExtensions.<RCTaskProxy>operator_doubleArrow(rCTaskProxy, _function);
  }
  
  public void beforeTaskDelete(final Task task) {
    IGenericQuery<RCTaskProxy> query=getObjectFactory().createGenericQuery(RCTaskProxy.class,"select tp from com.shrct.businessprocess.common.impl.RCTaskProxyImpl as tp   where ((tp.task) = (:task)) and  tp.active = 1      ").setParameter("task",task);
    RCTaskProxy rcTask = query.uniqueResult();getObjectFactory().delete(rcTask);
    
  }
}
